// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import HeroContact, {colliderGroup} from "./HeroContact";
import {animName} from "./HeroControl";
import Music, {musicName} from "../PublicScript/Music";

const {ccclass, property} = cc._decorator;

@ccclass
export default class MagicDoor extends cc.Component {

    @property({type:cc.Node, tooltip: "传送出现点"})
    destination: cc.Node = null;

    // onLoad () {}

    start () {

    }

    // 只在两个碰撞体结束接触时被调用一次
    onBeginContact(contact, self, other) {
        if(other.node.group == colliderGroup.hero || other.node.group == colliderGroup.box){
            Music.GamePlayEffect(musicName.chuansongme);
            this.scheduleOnce(()=>{
                let worldPos = this.destination.convertToWorldSpaceAR(this.destination.getPosition());
                let pos = cc.find("Canvas").convertToNodeSpaceAR(worldPos);
                other.node.setPosition(pos);
            },0.1);
        }
    }

    // update (dt) {}
}
